package com.zxy.ziems.server.energy.controller;

import com.zxy.btp.common.response.JsonResponse;
import com.zxy.btp.common.response.PageResult;
import com.zxy.ziems.server.energy.pojo.dto.EnergyPriceDTO;
import com.zxy.ziems.server.energy.pojo.dto.EnergyPriceTagDTO;
import com.zxy.ziems.server.energy.pojo.param.EnergyPriceQueryParam;
import com.zxy.ziems.server.energy.pojo.vo.EnergyPriceTagVO;
import com.zxy.ziems.server.energy.pojo.vo.EnergyPriceVO;
import com.zxy.ziems.server.energy.service.EnergyPriceService;
import com.zxy.ziems.server.energy.service.EnergyPriceTimeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 能源单价
 */
@RestController
@RequestMapping("/api/energyPrice")
public class EnergyPriceController {

    @Autowired
    private EnergyPriceService energyPriceService;
    @Autowired
    private EnergyPriceTimeService energyPriceTimeService;

    /**
     * 新增能源单价
     * @param energyPriceParam
     * @return
     */
    @PostMapping("/add")
    public JsonResponse<Void> add(@Validated(value = EnergyPriceDTO.Add.class) @RequestBody EnergyPriceDTO energyPriceParam) {
        energyPriceService.add(energyPriceParam);
        return JsonResponse.SUCCESS();
    }

    /**
     * 修改能源单价
     * @param energyPriceParam
     * @return
     */
    @PostMapping("/modify")
    public JsonResponse<Void> modify(@Validated(value = EnergyPriceDTO.Modify.class) @RequestBody EnergyPriceDTO energyPriceParam) {
        energyPriceService.modify(energyPriceParam);
        return JsonResponse.SUCCESS();
    }

    /**
     * 能源列表
     * @param energyPriceParam
     * @return
     */
    @PostMapping("/page")
    public PageResult<EnergyPriceVO> page(@Validated @RequestBody EnergyPriceQueryParam energyPriceParam) {
        return energyPriceService.page(energyPriceParam);
    }

    /**
     * 删除能源单价
     * @param dto
     * @return
     */
    @PostMapping("/remove")
    public JsonResponse<Void> remove(@Validated(value = EnergyPriceDTO.Delete.class) @RequestBody EnergyPriceDTO dto) {
        energyPriceService.remove(dto.getId());
        return JsonResponse.SUCCESS();
    }

    /**
     * 新增能源分段
     * @param energyPriceTimeDTO
     * @return
     */
    @PostMapping("/addOrModifyTime")
    public JsonResponse<Void> addOrModifyTime(@Validated @RequestBody List<EnergyPriceTagDTO> energyPriceTimeDTO) {
        energyPriceTimeService.addOrModifyTime(energyPriceTimeDTO);
        return JsonResponse.SUCCESS();
    }

    /**
     * 查看能源单价分段数据
     * @param energyPriceId
     * @return
     */
    @GetMapping("/getEnergyPriceTime")
    public JsonResponse<List<EnergyPriceTagVO>> getEnergyPriceTime(@RequestParam String energyPriceId) {
        return JsonResponse.SUCCESS(energyPriceTimeService.getEnergyPriceTime(energyPriceId));
    }

}
